package com.ysy.logistics.entities.system.vo;

import com.ysy.common.util.SaltMD5Util;
import com.ysy.logistics.entities.system.SysUser;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;

/**
 * @ClassDescription:
 * @Author:姚斯羽
 * @Create:2025/3/12 14:38
 **/
@Data
@Schema(name = "register",description = "注册实体类")
public class RegisterVO {

    @Schema(description = "用户名")
    @NotBlank(message = "用户名不能为空")
    @Size(min = 3, max = 20, message = "用户名长度必须在3到20个字符之间")
    @Pattern(regexp = "^[a-zA-Z0-9_]*$", message = "用户名只能包含字母、数字和下划线")
    private String username;

    @Schema(description = "密码")
    @NotBlank(message = "密码不能为空")
    @Size(min = 6,max = 16,message = "密码长度在6-16位之间")
    private String password;

    @Schema(description = "昵称")
    private String nickname;
    @Schema(description = "头像")
    private String avatar;

    @Schema(description = "电话")
    private String phone;

    @Schema(description = "状态")
    private String status;

    @Schema(description = "性别")
    private String sex;


    /**
     * 注册VO转SysUser
     * @param registerVO
     * @return
     */
    public static SysUser convertToSysUser(RegisterVO registerVO){
        SysUser sysUser = new SysUser();
        sysUser.setUsername(registerVO.getUsername());
        //密码加密
        sysUser.setPassword(SaltMD5Util.generateSaltPassword(registerVO.getPassword()));

        sysUser.setNickname(registerVO.getNickname());
        sysUser.setAvatar(registerVO.getAvatar());
        sysUser.setPhone(registerVO.getPhone());
        sysUser.setSex(registerVO.getSex());
        return sysUser;
    }
}
